<!--评价学员-->
<template>
  <el-drawer
    v-model="open"
    title="点评记录"
    :with-header="true"
    size="90%"
    class="dimension-drawer"
    :append-to-body="true"
    :close-on-click-modal="false"
    :before-close="closeW"
  >
    <div class="content">
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
        label-width="100px"
      >
        <el-form-item label="搜索学员" prop="name">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入学员姓名"
            clearable
            style="width: 240px"
            @keyup.enter="getList"
          >
            <template #append>
              <el-button :icon="Search" @click="getList" />
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="所在班级" prop="classId">
          <el-select
            v-model="queryParams.classId"
            placeholder="请选择所在班级"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="item in classList"
              :key="item.id"
              :label="item.beOver === '0' ? item.name + '(已结业)' : item.name"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="主班老师" prop="teacher">
          <el-select
            v-model="queryParams.teacher"
            placeholder="请选择主班老师"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="item in teacherList"
              :key="item.value"
              :label="
                !item.isJob
                  ? item.label + '(已离职)'
                  : !item.isTeacher
                  ? item.label + '(非授课)'
                  : item.label
              "
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="助教老师" prop="assistant">
          <el-select
            v-model="queryParams.assistant"
            placeholder="请选择助教老师"
            clearable
            style="width: 240px"
          >
            <el-option
              v-for="item in teacherList"
              :key="item.value"
              :label="
                !item.isJob
                  ? item.label + '(已离职)'
                  : !item.isTeacher
                  ? item.label + '(非授课)'
                  : item.label
              "
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="评价日期" prop="classDate">
          <el-date-picker
            v-model="classDate"
            type="daterange"
            range-separator="~"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="classDateRangeChange"
            value-format="YYYY-MM-DD"
            style="width: 240px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">
            搜索
          </el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList">
        </right-toolbar>
      </el-row>

      <el-table v-loading="loading" :data="list" border>
        <el-table-column label="评价时间" align="center" prop="createDate" />
        <el-table-column label="班级名称" align="center" prop="className" />
        <el-table-column label="主班老师" align="center" prop="teacherName" />
        <el-table-column label="助教老师" align="center" prop="assistantName" />
        <el-table-column label="内容" align="center" prop="description">
          <template #default="scope">
            <span
              @click="handleView(scope.row)"
              style="cursor: pointer; color: rgb(64, 158, 255)"
            >
              {{ scope.row.description }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="学员姓名" align="center" prop="studentName" />
        <!-- <el-table-column label="查看状态" align="center" prop="state" /> -->
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
    <CommentDetail ref="detailRef" />
  </el-drawer>
</template>

<script setup name="CommentStudent">
import { Search } from "@element-plus/icons-vue";
import { getPeopleList } from "@/api/studentManagement/index.js";
import { getClassListAPI } from "@/api/registrar/class";
import { getEvaluationRecordListAPI } from "@/api/interaction/comment";

import CommentDetail from "./commentDetail.vue";

const { proxy } = getCurrentInstance();
const loading = ref(false);
const open = ref(false);
const showSearch = ref(true);
const total = ref(0);
const classDate = ref(null);

const list = ref([]);
const teacherList = ref([]);
const classList = ref([]);

const detailRef = ref(null);

const data = reactive({
  queryParams: {
    type: 1, // 评价类型1学生评价2老师评价
    pageNum: 1,
    pageSize: 10,
    classId: "",
    teacher: null,
    assistant: null,
    classStartTime: null,
    classEndTime: null,
    name: null,
  },
});

const { queryParams } = toRefs(data);

// 事件-----------------------------------------------------------------------------------------------------------

function closeW() {
  open.value = false;
}

function openW() {
  initPage();
  open.value = true;
}

function classDateRangeChange(event) {
  classDate.value = event;
  queryParams.value.classStartTime = event ? event[0] : null;
  queryParams.value.classEndTime = event ? event[1] : null;
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  queryParams.value = {
    type: 1,
    pageNum: 1,
    pageSize: 10,
    classId: "",
    teacher: null,
    assistant: null,
    classStartTime: null,
    classEndTime: null,
    name: null,
  };
  classDate.value = null;
  getList();
}

// 查看
function handleView(row) {
  detailRef.value.openW(row);
}

// 方法-----------------------------------------------------------------------------------------------------------
// 获取教师列表
function getTeacherList() {
  loading.value = true;
  getPeopleList({ isTeach: 1 }).then((response) => {
    teacherList.value = response.data;
    loading.value = false;
  });
}

// 班级
function getClassList() {
  loading.value = true;
  getClassListAPI({ pageSize: 9999, pageNum: 1 }).then((response) => {
    classList.value = response.rows;
    loading.value = false;
  });
}

// 列表查询
function getList() {
  loading.value = true;
  getEvaluationRecordListAPI(proxy.addDateRange(queryParams.value, [])).then(
    (response) => {
      list.value = response.rows;
      total.value = response.total;
      loading.value = false;
    }
  );
}

function initPage() {
  queryParams.value.pageNum = 1;
  getTeacherList();
  getClassList();
  getList();
}

defineExpose({ openW }); // 用于父组件调用
// 初始化-------------------------------------------------------------------------------------------------------
</script>

<style lang="scss" scoped></style>
